import useApiFetch from '~/hooks/useApiFetch';

export type MatchItem = {
  createTime: string;
  matchData: MatchData;
  matchId: number;
  matchTime: string;
  updateTime: string;
  MatchAnalysis: AnalysisItem[];
  status: MatchStatus;
  handicap: HandicapStatus;
  hadScore: string;
  fullScore: string;
  penaltyScore: string;
};
export type MatchData = {
  /** 比赛唯一标识符 */
  matchId: number;
  /** 比赛编号 */
  matchNum: string;
  /** 比赛时间 */
  matchTime: string;
  /** 星期几 */
  weekday: string;
  /** 联赛ID */
  leagueId: string;
  /** 联赛名称 */
  leagueName: string;
  /** 主队信息 */
  homeTeam: {
    /** 主队ID */
    id: string;
    /** 主队简称 */
    name: string;
    /** 主队全称 */
    fullName: string;
    /** 主队排名 */
    rank: string;
  };
  /** 客队信息 */
  awayTeam: {
    /** 客队ID */
    id: string;
    /** 客队简称 */
    name: string;
    /** 客队全称 */
    fullName: string;
    /** 客队排名 */
    rank: string;
  };
  /** 赔率信息 */
  odds: {
    /** 胜平负玩法赔率 */
    had: OddsItem;
    /** 让球胜平负玩法赔率 */
    hhad: OddsItem;
  };
};
export enum MatchStatus {
  NOT_STARTED = 'NOT_STARTED', /// 未开始
  WINNING = 'WINNING', /// 胜
  DRAW = 'DRAW', /// 平
  LOSING = 'LOSING', /// 负
}
export enum HandicapStatus {
  NOT_STARTED = 'NOT_STARTED', /// 未开始
  HANDICAP_WINNING = 'HANDICAP_WINNING', /// 让胜
  HANDICAP_DRAW = 'HANDICAP_DRAW', /// 让平
  HANDICAP_LOSING = 'HANDICAP_LOSING', /// 让负
}

/**
 * 赔率项接口
 */
export interface OddsItem {
  /** 客胜赔率 */
  a: string;
  /** 客胜赔率变化方向 (1: 上升, -1: 下降, 0: 无变化) */
  af: string;
  /** 平局赔率 */
  d: string;
  /** 平局赔率变化方向 */
  df: string;
  /** 让球线 */
  goalLine: string;
  /** 让球数值 */
  goalLineValue: string;
  /** 主胜赔率 */
  h: string;
  /** 主胜赔率变化方向 */
  hf: string;
  /** 更新日期 (YYYY-MM-DD) */
  updateDate: string;
  /** 更新时间 (HH:mm:ss) */
  updateTime: string;
}

const analysis_json = {
  rating: '评分，1-10分，分数越高，分析越准确',
  probabilities: {
    home_win: '主队获胜概率，百分比格式，例如 45.2%',
    draw: '平局概率，百分比格式，例如 30.5%',
    away_win: '客队获胜概率，百分比格式，例如 24.3%',
  },
  analysis_breakdown: {
    strength_and_form: '对实力与状态对比的文本分析',
    motivation: '对战意与动机的文本分析',
    key_factors: '影响比赛结果的关键因素分析，如伤停情况、战术克制、主客场因素、心理优势等',
  },
  most_likely_scorelines: ['最可能比分，例如 2-1,1-0 等，可以输出不超过四个'],
  final_investment_advice: '最终的综合性投资建议文本',
};
export type AnalysisJson = typeof analysis_json;
export type AnalysisItem = {
  matchId: number;
  analysisData: AnalysisJson;
  createTime: string;
  updateTime: string;
};

export enum CombinationStatus {
  NOT_STARTED = 'NOT_STARTED',
  WINNING = 'WINNING',
  LOSING = 'LOSING',
}
export enum CombinationType {
  TWO_LEG = 'TWO_LEG', /// 二串一
  THREE_LEG = 'THREE_LEG',
  FOUR_LEG = 'FOUR_LEG',
  FIVE_LEG = 'FIVE_LEG',
  HIGH_ODDS = 'HIGH_ODDS',
}

export type RecommendItem = {
  id: string;
  type: CombinationType;
  score: number;
  advice: string;
  combinationData: CombinationItem[];
  createTime: string;
  updateTime: string;
  status: CombinationStatus;
};
export type CombinationItem = {
  matchId: string;
  prediction: string; // 胜/平/负/让球胜/让球平/让球负
};

// 1 获取今日足球比赛列表(传递如 2025-10-10 格式)
export const getTodayFootballList = (params: { date?: string; onlyToday?: boolean } = {}) => {
  return useApiFetch<ResOptions<MatchItem[]>>('/football/getDailyMatches', { method: 'POST', params });
};

// 2 获取今日足球比赛分析
export const getTodayFootballAnalysis = (matchId?: number) => {
  return useApiFetch<ResOptions<AnalysisItem & { Match: Omit<MatchItem, 'MatchAnalysis'> }>>('/football/getMatchAnalysis', {
    method: 'POST',
    body: { matchId },
  });
};

// 3 获取今日足球比赛推荐组合
export const getTodayFootballRecommend = () => {
  return useApiFetch<ResOptions<RecommendItem[]>>('/football/getDailyRecommend', { method: 'POST' });
};
